<?php
/* 接收json数据 */
require("../../utils/resolve_json.php");
/* sql操作工具 */
require("../../utils/tools.php");
$re_data = array();

if (!isset($data["id"])) {
    $code = 3000;
    $msg = "注册失败,账户不能为空!";
} else {
    if (!isset($data["pd"])) {
        $code = 3001;
        $msg = "注册失败,密码不能为空!";
    } else {
        if (!isset($data["email"])) {
            $code = 3002;
            $msg = "注册失败,邮箱不能为空!";
        } else {
            if(SQLTools::existTB($conn, 'users',"id='${data["id"]}'")){
                $code = 3003;
                $msg = "注册失败,id已存在!";
            }else {
                $data["pd"] = password_hash(md5($data["pd"]), PASSWORD_DEFAULT);//双重密码加密
                $token = create_token_sql($conn, 'users', 'token'); // 创建一个不重复的token
                $uuid = SQLTools::$SQL_UUID;
                if (SQLTools::insertTB($conn, 'users', 'uuid,id,pd,email,req_time,login_time,reg_time,token', "$uuid,'${data["id"]}','${data["pd"]}','${data["email"]}',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,'$token'")) {
                    $code = 2000;
                    $msg = "注册成功!";
                    $re_data = array("id" => $data["id"], "token" => $token);
                } else {
                    $code = 3033;
                    $msg = "注册失败,原因未知!";
                }
            }
          
        }
    }
}
$result = array("code" => $code, "msg" => $msg, "data" => $re_data);
echo json_encode_mz_urlencode($result);
